package com.shujia.day13;

import java.io.File;
import java.io.IOException;

public class Code08File {
    public static void main(String[] args) throws IOException {
        /*
            File常见的成员方法：
            创建功能
                public boolean createNewFile()
                public boolean mkdir()
                public boolean mkdirs()  // 创建多级目录
            删除功能
                public boolean delete()
            重命名功能
                public boolean renameTo(File dest)
         */

        File data = new File("data/b.txt");
//        boolean newFile = false;
//        try {
//            newFile = data.createNewFile();
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }

        boolean newFile = data.createNewFile();

        /*
            public boolean createNewFile() throws IOException {  // 抛给调用者
                SecurityManager security = System.getSecurityManager();
                if (security != null) security.checkWrite(path);
                if (isInvalid()) {
                    throw new IOException("Invalid file path");  // 抛出一个异常对象
                }
                return fs.createFileExclusively(path);
            }
         */

        System.out.println(newFile);


        File file = new File("data/a");
        file.mkdir();

        File file1 = new File("data/b/c/d");
        file1.mkdirs();

        file1.delete();

        File file2 = new File("data/b/c");
        file2.renameTo(new File("data/b/nextFile"));

    }
}
